<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0018)http://www.sql.su/ -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>SQL (Structured Query Language) in one page : SQL.SU</title>
    
  <meta name="description" content="SQL (Structured Query Language) in one page : SQL.SU">
  <meta name="keywords" content="SQL (Structured Query Language) in one page : SQL.SU : SQL use to access and manipulate data in Oracle, Sybase, Microsoft SQL Server, DB2, Access, MySQL, PostgreSQL and other database systems">
  <link rel="stylesheet" type="text/css" href="./SQL (Structured Query Language) in one page   SQL.SU_files/sql.css">
 </head>

 <body>
  <table align="center"><!-- cellspacing="3" -->
   <tbody><tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
   </tr>
	 
   <tr><td colspan="4" class="titleMain">SQL&nbsp;(Structured&nbsp;Query&nbsp;Language)&nbsp;in&nbsp;one&nbsp;page</td></tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
   </tr>
   
   <tr>
    <td class="normalizerEmpty">&nbsp;</td>
    <td colspan="2" class="contents">
	 <b>Contents:</b><br>
	 &nbsp;&nbsp;&nbsp;&nbsp;<b>Review:</b> <a href="http://www.sql.su/#faq">FAQ</a>;<br>
	 &nbsp;&nbsp;&nbsp;&nbsp;<b>Table of contents:</b> <a href="http://www.sql.su/#database_manipulation">Database Manipulation (CREATE, DROP DATABASE)</a>,
	 <a href="http://www.sql.su/#table_manipulation">Table Manipulation (CREATE, ALTER, DROP TABLE, Data Types)</a>,
	 <a href="http://www.sql.su/#index_manipulation">Index Manipulation (CREATE, DROP INDEX)</a>,
	 <a href="http://www.sql.su/#data_manipulation">Data Manipulation (INSERT, UPDATE, DELETE, TRUNCATE TABLE)</a>,
	 <a href="http://www.sql.su/#select">Select (SELECT, FROM, WHERE, ORDER BY, GROUP BY, HAVING, Operators, Aggregate functions)</a>,
	 <a href="http://www.sql.su/#alias">Alias</a>,
	 <a href="http://www.sql.su/#join">Join</a>,
	 <a href="http://www.sql.su/#union">UNION</a>,
	 <a href="http://www.sql.su/#into">SELECT INTO/IN</a>,
	 <a href="http://www.sql.su/#view">CREATE VIEW</a>;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<b>Similar Sites:</b> 
<a href="http://www.manual.su/">MANUAL</a>, 
<a href="http://www.cheat-sheets.org/">Cheat sheets</a>,
<a href="http://www.html.su/">HTML</a>, 
<a href="http://www.css.su/">CSS</a>, 
<a href="http://www.xml.su/">XML</a>, 
<a href="http://www.xml.su/dtd.html">DTD</a>,
<a href="http://www.javascript.su/">JavaScript</a>,  
<a href="http://www.w3cdom.org/">W3C DOM</a>,
<a href="./SQL (Structured Query Language) in one page   SQL.SU_files/SQL (Structured Query Language) in one page   SQL.SU.htm">SQL</a>,   
<a href="http://www.ssi.su/">SSI</a>, 
<a href="http://www.tell.su/">Tell a friend</a>,
<a href="http://www.iconsfree.org/">Free Icons</a>,  
<a href="http://www.itlibitum.org/">Itlibitum, Corp.</a>.
	</td>
    <td><div class="normalizer">&nbsp;</div></td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
   </tr>
	 
   <tr>
    <td class="empty">&nbsp;</td>
    <td rowspan="2" colspan="2" align="center">
	 <table align="center">
	  <tbody><tr>
	   <td>
<!--Google adsence-referals-adsence-©-begin-->	
<script type="text/javascript"><!--
google_ad_client = "pub-1858423611892674";
google_ad_width = 120;
google_ad_height = 240;
google_ad_format = "120x240_as_rimg";
google_cpa_choice = "CAAQg6aazgEaCByzL-E9BzG1KOPC93M";
//--></script>
<script type="text/javascript" src="./SQL (Structured Query Language) in one page   SQL.SU_files/show_ads.js">
</script><ins style="display:inline-table;border:none;height:240px;margin:0;padding:0;position:relative;visibility:visible;width:120px;background-color:transparent"><ins id="aswift_0_anchor" style="display:block;border:none;height:240px;margin:0;padding:0;position:relative;visibility:visible;width:120px;background-color:transparent"><iframe width="120" height="240" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_0" name="aswift_0" style="left:0;position:absolute;top:0;"></iframe></ins></ins>
<!--Google adsence-referals-adsence-©-end-->	   
	   </td>
	   <td>
<!--Google adsence-adsence-©-begin-->	
<script type="text/javascript"><!--
google_ad_client = "pub-1858423611892674";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "CCCCCC";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_url = "666666";
google_color_text = "333333";
//--></script>
<script type="text/javascript" src="./SQL (Structured Query Language) in one page   SQL.SU_files/show_ads.js">
</script><ins style="display:inline-table;border:none;height:250px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent"><ins id="aswift_1_anchor" style="display:block;border:none;height:250px;margin:0;padding:0;position:relative;visibility:visible;width:300px;background-color:transparent"><iframe width="300" height="250" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_1" name="aswift_1" style="left:0;position:absolute;top:0;"></iframe></ins></ins>
<!--Google adsence-adsence-©-end-->	
	   </td>
	   <td>
<!--Google adsence-referals-firefox-©-begin-->	
<script type="text/javascript"><!--
google_ad_client = "pub-1858423611892674";
google_ad_width = 120;
google_ad_height = 240;
google_ad_format = "120x240_as_rimg";
google_cpa_choice = "CAAQjeWZzgEaCGUPemYRwK8bKPG193M";
//--></script>
<script type="text/javascript" src="./SQL (Structured Query Language) in one page   SQL.SU_files/show_ads.js">
</script><ins style="display:inline-table;border:none;height:240px;margin:0;padding:0;position:relative;visibility:visible;width:120px;background-color:transparent"><ins id="aswift_2_anchor" style="display:block;border:none;height:240px;margin:0;padding:0;position:relative;visibility:visible;width:120px;background-color:transparent"><iframe width="120" height="240" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_2" name="aswift_2" style="left:0;position:absolute;top:0;"></iframe></ins></ins>
<!--Google adsence-referals-firefox-©-end-->	
	   </td>
	  </tr>
	  <tr><td colspan="3">&nbsp;</td></tr>
	  <tr>
	   <td colspan="3" align="center">
<!-- Search Google -->
<center>
<form method="get" action="http://www.google.com/custom" target="_top">
<table bgcolor="#ffffff">
<tbody><tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="./SQL (Structured Query Language) in one page   SQL.SU_files/Logo_25wht.gif" border="0" alt="Google" align="middle"></a>
<input type="text" name="q" size="31" maxlength="255" value="">
<input type="submit" name="sa" value="Search">
<input type="hidden" name="client" value="pub-1858423611892674">
<input type="hidden" name="forid" value="1">
<input type="hidden" name="ie" value="UTF-8">
<input type="hidden" name="oe" value="UTF-8">
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;">
<input type="hidden" name="hl" value="en">
</td></tr></tbody></table>
</form>
</center>
<!-- Search Google -->	   
	   </td>
	  </tr>
	  <tr><td colspan="3">&nbsp;</td></tr>
	  <tr>
	   <td colspan="3" align="center">
<!--Google AdSence Context-©-begin-->	
<script type="text/javascript"><!--
google_ad_client = "pub-1858423611892674";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as_rimg";
google_cpa_choice = "CAAQnJT88AEaCMK4_ISyftj8KKSxynM";
//--></script>
<script type="text/javascript" src="./SQL (Structured Query Language) in one page   SQL.SU_files/show_ads.js">
</script><ins style="display:inline-table;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px;background-color:transparent"><ins id="aswift_3_anchor" style="display:block;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px;background-color:transparent"><iframe width="468" height="60" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){try{h=s.upd(h,i)}catch(e){}w.location.replace(h)}}" id="aswift_3" name="aswift_3" style="left:0;position:absolute;top:0;"></iframe></ins></ins>
<!--Google AdSence Context-©-end-->   
	   </td>
	  </tr>
	 </tbody></table>
	</td>
    <td class="titleChapter">&nbsp;<a name="faq">&nbsp;</a>FAQ</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<!--2 cell-->
	<td class="description">
	 <div class="note">What is SQL?</div>
	 <ul>
	  <li>SQL stands for Structured Query Language;</li>
	  <li>SQL allows you to access a database;</li>
	  <li>SQL is an ANSI standard computer language;</li>
	  <li>SQL use to access and manipulate data in Oracle, Sybase, Microsoft SQL Server, DB2, Access, MySQL, PostgreSQL and other database systems;</li>
	  <li>SQL can execute queries against a database;</li>
	  <li>SQL can retrieve data from a database;</li>
	  <li>SQL can insert new records in a database;</li>
	  <li>SQL can delete records from a database;</li>
	  <li>SQL can update records in a database;</li>
	  <li>SQL is easy to learn.</li>
	 </ul> 
	</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="database_manipulation">&nbsp;</a>Database Manipulation </td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">CREATE DATABASE <span class="inputData">database_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Create a database</td>
    <td class="example">CREATE DATABASE My_First_Database</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">DROP DATABASE <span class="inputData">database_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delete a database</td>
    <td class="example">DROP DATABASE My_First_Database</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="table_manipulation">&nbsp;</a>Table Manipulation</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td rowspan="2" class="code">CREATE TABLE "<span class="inputData">table_name</span>"<br>("<span class="inputData">column_1</span>" "<span class="inputData">data_type_for_column_1</span>",<br>"<span class="inputData">column_2</span>" "<span class="inputData">data_type_for_column_2</span>",<br>... )</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Create a table in a database.</td>
    <td rowspan="2" class="example">CREATE TABLE Person<br>(LastName varchar,<br>FirstName varchar,<br>Address varchar,<br>Age int)</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<!--1 cell-->
    <td class="description">
	 <table cellspacing="0" class="tableDescription">
	  <caption>Data Types</caption>
	  <tbody><tr><th>Data Type</th><th>Description</th></tr>
	  <tr><td>integer(size)</td><td rowspan="4">&nbsp;&nbsp;&nbsp;&nbsp;Hold integers only. The maximum number of digits are specified in parenthesis.</td></tr>
	  <tr><td>int(size)</td><!--1 cell--></tr>
	  <tr><td>smallint(size)</td><!--1 cell--></tr>
	  <tr><td>tinyint(size)</td><!--1 cell--></tr>
	  <tr><td>decimal(size,d)</td><td rowspan="2">&nbsp;&nbsp;&nbsp;&nbsp;Hold numbers with fractions. The maximum number of digits are specified in "size". The maximum number of digits to the right of the decimal is specified in "d".</td></tr>
	  <tr><td>numeric(size,d)</td><!--1 cell--></tr>
	  <tr><td>char(size)</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis.</td></tr>
	  <tr><td>varchar(size)</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis.</td></tr>
	  <tr><td>date(yyyymmdd)</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Holds a date</td></tr>
	 </tbody></table>
	</td>
	<!--1 cell-->
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">ALTER TABLE <span class="inputData">table_name</span> ADD <span class="inputData">column_name</span> <span class="inputData">datatype</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add columns in an existing table.</td>
    <td class="example">ALTER TABLE Person ADD Sex char(6)</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">ALTER TABLE <span class="inputData">table_name</span> DDROP <span class="inputData">column_name</span> <span class="inputData">datatype</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delete columns in an existing table.</td>
    <td class="example">ALTER TABLE Person DROP Sex char(6)</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">DROP TABLE <span class="inputData">table_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delete a table.</td>
    <td class="example">DROP TABLE Person</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="index_manipulation">&nbsp;</a>Index Manipulation</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">CREATE INDEX <span class="inputData">index_name</span><br>ON <span class="inputData">table_name</span> (<span class="inputData">column_name_1</span>, <span class="inputData">column_name_2</span>, ...)</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Create a simple index.</td>
    <td class="example">CREATE INDEX PersonIndex<br>ON Person (LastName, FirstName)</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">CREATE UNIQUE INDEX <span class="inputData">index_name</span><br>ON <span class="inputData">table_name</span> (<span class="inputData">column_name_1</span>, <span class="inputData">column_name_2</span>, ...)</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Create a unique index.</td>
    <td class="example">CREATE UNIQUE INDEX PersonIndex<br>ON Person (LastName DESC)</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">DROP INDEX <span class="inputData">table_name.index_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delete a index.</td>
    <td class="example">DROP INDEX Person.PersonIndex</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="data_manipulation">&nbsp;</a>Data Manipulation</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">INSERT INTO <span class="inputData">table_name</span><br>VALUES (<span class="inputData">value_1</span>, <span class="inputData">value_2</span>,....)</td>
    <td rowspan="2" class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insert new rows into a table.</td>
    <td class="example">INSERT INTO Persons<br>VALUES('Hussein', 'Saddam', 'White House')</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">INSERT INTO <span class="inputData">table_name</span> (<span class="inputData">column1</span>, <span class="inputData">column2</span>,...)<br>VALUES (<span class="inputData">value_1</span>, <span class="inputData">value_2</span>,....)</td>
    <!--1 cell-->
    <td class="example">INSERT INTO Persons (LastName, FirstName, Address)<br>VALUES('Hussein', 'Saddam', 'White House')</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">UPDATE <span class="inputData">table_name</span><br>SET <span class="inputData">column_name_1</span> = <span class="inputData">new_value_1</span>, <span class="inputData">column_name_2</span> = <span class="inputData">new_value_2</span><br>WHERE <span class="inputData">column_name</span> = <span class="inputData">some_value</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Update one or several columns in rows.</td>
    <td class="example">UPDATE Person<br>SET Address = 'ups'<br>WHERE LastName = 'Hussein'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">DELETE FROM <span class="inputData">table_name</span><br>WHERE <span class="inputData">column_name</span> = <span class="inputData">some_value</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delete rows in a table.</td>
    <td class="example">DELETE FROM Person WHERE LastName = 'Hussein'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">TRUNCATE TABLE <span class="inputData">table_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deletes the data inside the table.</td>
    <td class="example">TRUNCATE TABLE Person</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="select">&nbsp;</a>Select</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT <span class="inputData">column_name(s)</span> FROM <span class="inputData">table_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select data from a table.</td>
    <td class="example">SELECT LastName, FirstName FROM Persons</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT * FROM <span class="inputData">table_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select all data from a table.</td>
    <td class="example">SELECT * FROM Persons</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT DISTINCT <span class="inputData">column_name(s)</span> FROM <span class="inputData">table_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select only distinct (different) data from a table.</td>
    <td class="example">SELECT DISTINCT LastName, FirstName FROM Persons</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td rowspan="8" class="code">SELECT <span class="inputData">column_name(s)</span> FROM <span class="inputData">table_name</span><br>
	WHERE <span class="inputData">column</span> <span class="inputData">operator</span> <span class="inputData">value</span><br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND <span class="inputData">column</span> <span class="inputData">operator</span> <span class="inputData">value</span><br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OR <span class="inputData">column</span> <span class="inputData">operator</span> <span class="inputData">value</span><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND (... OR ...)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select only certain data from a table.</td>
    <td class="example">SELECT * FROM Persons WHERE sex='female'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <td rowspan="7" class="description">
	 <table cellspacing="0" class="tableDescription">
	  <caption>Operators</caption>
	  <tbody><tr><th>Operator</th><th>Description</th></tr>
	  <tr><td>=</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Equal</td></tr>
	  <tr><td>&lt;&gt;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Not equal</td></tr>
	  <tr><td>&gt;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Greater than</td></tr>
	  <tr><td>&lt;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Less than</td></tr>
	  <tr><td>&gt;=</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Greater than or equal</td></tr>
	  <tr><td>&lt;=</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Less than or equal</td></tr>
	  <tr><td>BETWEEN</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Between an inclusive range</td></tr>
	  <tr><td>LIKE</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Search for a pattern.<br>A "%" sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern.</td></tr>
	 </tbody></table>
	</td>
    <td class="example">SELECT * FROM Persons WHERE Year&gt;1970</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <!--1 cell-->
    <td class="example">SELECT * FROM Persons<br>WHERE FirstName='Saddam'<br>AND LastName='Hussein'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <!--1 cell-->
    <td class="example">SELECT * FROM Persons<br>WHERE FirstName='Saddam'<br>OR LastName='Hussein'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <!--1 cell-->
    <td class="example">SELECT * FROM Persons WHERE<br>(FirstName='Tove' OR FirstName='Stephen')<br>AND LastName='Svendson'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <!--1 cell-->
    <td class="example">SELECT * FROM Persons WHERE FirstName LIKE 'O%'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <!--1 cell-->
    <td class="example">SELECT * FROM Persons WHERE FirstName LIKE '%a'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <!--1 cell-->
    <td class="example">SELECT * FROM Persons WHERE FirstName LIKE '%la%'</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT <span class="inputData">column_name(s)</span> FROM <span class="inputData">table_name</span><br>
    WHERE <span class="inputData">column_name</span> IN (<span class="inputData">value1</span>, <span class="inputData">value2</span>, ...)</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The IN operator may be used if you know the exact value you want to return for at least one of the columns.</td>
    <td class="example">SELECT * FROM Persons<br>WHERE LastName IN ('Hansen','Pettersen')</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td rowspan="3" class="code">SELECT <span class="inputData">column_name(s)</span> FROM <span class="inputData">table_name</span><br>ORDER BY <span class="inputData">row_1</span>, <span class="inputData">row_2</span> DESC, <span class="inputData">row_3</span> ASC, ...</td>
    <td rowspan="3" class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select data from a table with sort the rows.<br>
      <br><div class="note">Note:</div><ul><li><span class="note">ASC</span> (ascend) is a alphabetical and numerical order (optional)</li><li><span class="note">DESC</span> (descend) is a reverse alphabetical and numerical order</li></ul></td>
    <td class="example">SELECT * FROM Persons<br>ORDER BY LastName</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <!--1 cell-->
    <td class="example">SELECT FirstName, LastName FROM Persons<br>ORDER BY LastName DESC</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <!--1 cell-->
    <td class="example">SELECT Company, OrderNumber FROM Orders<br>ORDER BY Company DESC, OrderNumber ASC</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td rowspan="2" class="code">SELECT <span class="inputData">column_1</span>, ..., SUM(<span class="inputData">group_column_name</span>)<br>
     FROM <span class="inputData">table_name</span><br>GROUP BY <span class="inputData">group_column_name</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GROUP BY... was added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called, and without the GROUP BY function it was impossible to find the sum for each individual group of column values.</td>
    <td rowspan="2" class="example">SELECT Company, SUM(Amount) <br>FROM Sales <br>GROUP BY Company</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <!--1 cell-->
    <td class="description">
	 <table cellspacing="0" class="tableDescription">
	  <caption>Some aggregate functions</caption>
	  <tbody><tr><th>Function</th><th>Description</th></tr>
	  <tr><td>AVG(column)</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Returns the average value of a column</td></tr>
	  <tr><td>COUNT(column)</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Returns the number of rows (without a NULL value) of a column</td></tr>
	  <tr><td>MAX(column)</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Returns the highest value of a column</td></tr>
	  <tr><td>MIN(column)</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Returns the lowest value of a column</td></tr>
	  <tr><td>SUM(column)</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Returns the total sum of a column</td></tr>
	</tbody></table>
	</td>
    <!--1 cell-->
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT <span class="inputData">column_1</span>,  ..., SUM(<span class="inputData">group_column_name</span>)<br>
     FROM <span class="inputData">table_name</span><br>GROUP BY <span class="inputData">group_column_name</span><br>HAVING SUM(<span class="inputData">group_column_name</span>) <span class="inputData">condition</span> <span class="inputData">value</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HAVING... was added to SQL because the WHERE keyword could not be used against aggregate functions (like SUM), and without HAVING... it would be impossible to test for result conditions.</td>
    <td class="example">SELECT Company, SUM(Amount)<br>FROM Sales <br>GROUP BY Company <br>HAVING SUM(Amount)&gt;10000</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="alias">&nbsp;</a>Alias</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT <span class="inputData">column_name</span> AS <span class="inputData">column_alias</span> FROM <span class="inputData">table_name</span></td>
    <td class="description">Column name alias</td>
    <td class="example">SELECT LastName AS Family, FirstName AS Name<br>FROM Persons</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT <span class="inputData">table_alias.column_name</span> FROM <span class="inputData">table_name</span> AS <span class="inputData">table_alias</span></td>
    <td class="description">Table name alias</td>
    <td class="example">SELECT LastName, FirstName<br>FROM Persons AS Employees</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="join">&nbsp;</a>Join</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">
	 SELECT <span class="inputData">column_1_name</span>, <span class="inputData">column_2_name</span>, ...<br>
	 FROM <span class="inputData">first_table_name</span><br>
	 INNER JOIN <span class="inputData">second_table_name</span><br>
	 ON <span class="inputData">first_table_name.keyfield</span> = <span class="inputData">second_table_name.foreign_keyfield</span>
	</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	 The INNER JOIN returns all rows from both tables where there is a match. 
	 If there are rows in first table that do not have matches in second table, those rows will not be listed.
	</td>
    <td class="example">
	 SELECT Employees.Name, Orders.Product<br>
	 FROM Employees<br>
	 INNER JOIN Orders<br>
	 ON Employees.Employee_ID=Orders.Employee_ID
	</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">
	 SELECT <span class="inputData">column_1_name</span>, <span class="inputData">column_2_name</span>, ...<br>
	 FROM <span class="inputData">first_table_name</span><br>
	 LEFT JOIN <span class="inputData">second_table_name</span><br>
	 ON <span class="inputData">first_table_name.keyfield</span> = <span class="inputData">second_table_name.foreign_keyfield</span>
	</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	 The LEFT JOIN returns all the rows from the first table, even if there are no matches in the second table. 
	 If there are rows in first table that do not have matches in second table, those rows also will be listed.
	</td>
    <td class="example">
	 SELECT Employees.Name, Orders.Product<br>
	 FROM Employees<br>
	 LEFT JOIN Orders<br>
	 ON Employees.Employee_ID=Orders.Employee_ID
	</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">
	 SELECT <span class="inputData">column_1_name</span>, <span class="inputData">column_2_name</span>, ...<br>
	 FROM <span class="inputData">first_table_name</span><br>
	 RIGHT JOIN <span class="inputData">second_table_name</span><br>
	 ON <span class="inputData">first_table_name.keyfield</span> = <span class="inputData">second_table_name.foreign_keyfield</span>
	</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	 The RIGHT JOIN returns all the rows from the second table, even if there are no matches in the first table. 
	 If there had been any rows in second table that did not have matches in first table, those rows also would have been listed.
	</td>
    <td class="example">
	 SELECT Employees.Name, Orders.Product<br>
	 FROM Employees<br>
	 RIGHT JOIN Orders<br>
	 ON Employees.Employee_ID=Orders.Employee_ID
	</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="union">&nbsp;</a>UNION</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code"><span class="inputData">SQL_Statement_1</span><br>UNION<br><span class="inputData">SQL_Statement_2</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select all different values from <span class="inputData">SQL_Statement_1</span> and <span class="inputData">SQL_Statement_2</span></td>
    <td class="example">SELECT E_Name FROM Employees_Norway<br>UNION<br>SELECT E_Name FROM Employees_USA</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code"><span class="inputData">SQL_Statement_1</span><br>UNION ALL<br><span class="inputData">SQL_Statement_2</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select all values from <span class="inputData">SQL_Statement_1</span> and <span class="inputData">SQL_Statement_2</span></td>
    <td class="example">SELECT E_Name FROM Employees_Norway<br>UNION<br>SELECT E_Name FROM Employees_USA</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="into">&nbsp;</a>SELECT INTO/IN</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT <span class="inputData">column_name(s)</span><br>INTO <span class="inputData">new_table_name</span><br>FROM <span class="inputData">source_table_name</span><br>WHERE <span class="inputData">query</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select data from table(S) and insert it into another table.</td>
    <td class="example">SELECT * INTO Persons_backup FROM Persons</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">SELECT <span class="inputData">column_name(s)</span><br>IN <span class="inputData">external_database_name</span><br>FROM <span class="inputData">source_table_name</span><br>WHERE <span class="inputData">query</span></td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select data from table(S) and insert it in another database.</td>
    <td class="example">SELECT Persons.* INTO Persons IN 'Backup.db' FROM Persons WHERE City='Sandnes'</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="view">CREATE VIEW</a> </td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td class="code">
	 CREATE VIEW <span class="inputData">view_name</span> AS<br>
	 SELECT <span class="inputData">column_name(s)</span><br>
	 FROM <span class="inputData">table_name</span><br>
	 WHERE <span class="inputData">condition</span>
	</td>
    <td class="description">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Create a virtual table based on the result-set of a SELECT statement.</td>
    <td class="example">
	 CREATE VIEW [Current Product List] AS<br>
	 SELECT ProductID, ProductName<br>
	 FROM Products<br>
	 WHERE Discontinued=No
	</td>
   </tr>
	  
   <tr>	
    <td><div class="normalizerEmpty">&nbsp;</div></td>
	<td colspan="3" class="titleChapter"><a name="other">&nbsp;</a>OTHER</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td colspan="3" class="description">	 
	    <table align="center">
		 <tbody><tr><td colspan="3" align="center"><b>© 2006 <a href="http://www.manual.su/">MANUAL.SU</a> (<a href="http://www.itlibitum.org/">Itlibitum, Corp.</a>)</b></td></tr>
		 <tr><td colspan="3" align="center">&nbsp;</td></tr>
		 <tr>
		  <td align="center"><a href="http://validator.w3.org/check?uri=http://www.sql.su/index.html"><img style="border:0;width:88px;height:31px" src="./SQL (Structured Query Language) in one page   SQL.SU_files/valid-xhtml10" alt="Valid XHTML 1.0 Transitional"></a></td>
		  <td align="center">&nbsp;</td>
		  <td align="center"><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.sql.su/index.html"><img style="border:0;width:88px;height:31px" src="./SQL (Structured Query Language) in one page   SQL.SU_files/vcss" alt="Valid CSS!"></a></td>
		 </tr>
		</tbody></table>
	</td>
   </tr>
	  
   <tr>	
    <td colspan="4" class="titleChapter">&nbsp;</td>
   </tr>
   
   <tr>
    <td><div class="normalizerEmpty">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
    <td><div class="normalizer">&nbsp;</div></td>
   </tr>
   
  </tbody></table>
  
<!--Google analytics-©-begin-->
<script src="./SQL (Structured Query Language) in one page   SQL.SU_files/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-181991-4";
urchinTracker();
</script>  
<!--Google analytics-©-end-->

 


</body></html>